package com.lrkj.property.controller;

import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.property.domain.ManageArea;
import com.lrkj.property.service.IManageAreaService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 管理区Controller
 *
 * @author yajun_ren
 * @date 2021-07-28
 */
@RestController
@RequestMapping("/property/area")
public class ManageAreaController extends BaseController
{
    @Autowired
    private IManageAreaService manageAreaService;

    /**
     * 查询管理区列表
     */
    @ApiOperation(value = "查询管理区列表", notes = "查询管理区列表")
    @PreAuthorize("@ss.hasPermi('property:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(ManageArea manageArea)
    {
        startPage();
        List<ManageArea> list = manageAreaService.selectManageAreaList(manageArea);
        return getDataTable(list);
    }

    /**
     * 导出管理区列表
     */
	@ApiOperation(value = "导出管理区列表", notes = "导出管理区列表")
    @PreAuthorize("@ss.hasPermi('property:area:export')")
    @Log(title = "管理区", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ManageArea manageArea)
    {
        List<ManageArea> list = manageAreaService.selectManageAreaList(manageArea);
        ExcelUtil<ManageArea> util = new ExcelUtil<ManageArea>(ManageArea.class);
        return util.exportExcel(list, "管理区数据");
    }

    /**
     * 获取管理区详细信息
     */
	@ApiOperation(value = "获取管理区详细信息", notes = "获取管理区详细信息")
    @PreAuthorize("@ss.hasPermi('property:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") String areaId)
    {
        return AjaxResult.success(manageAreaService.selectManageAreaById(areaId));
    }

    /**
     * 新增管理区
     */
	  @ApiOperation(value = "新增管理区", notes = "新增管理区")
    @PreAuthorize("@ss.hasPermi('property:area:add')")
    @Log(title = "管理区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManageArea manageArea)
    {
        return toAjax(manageAreaService.insertManageArea(manageArea));
    }

    /**
     * 修改管理区
     */
	 @ApiOperation(value = "修改管理区", notes = "修改管理区")
    @PreAuthorize("@ss.hasPermi('property:area:edit')")
    @Log(title = "管理区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManageArea manageArea)
    {
        return toAjax(manageAreaService.updateManageArea(manageArea));
    }

    /**
     * 删除管理区
     */
	 @ApiOperation(value = "删除管理区", notes = "删除管理区")
    @PreAuthorize("@ss.hasPermi('property:area:remove')")
    @Log(title = "管理区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable String[] areaIds)
    {
        return toAjax(manageAreaService.deleteManageAreaByIds(areaIds));
    }
}
